package com.sunlands.zlcx.usercenter.service.task;

import com.sunlands.zlcx.usercenter.domain.BuryingPointDO;
import com.sunlands.zlcx.usercenter.service.BuryingPointServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class TaskBuryingPointServiceImpl {
    @Value("${eureka.debug:false}")
    private Boolean debug;
    @Autowired
    private BuryingPointServiceImpl buryingPointService;

    @Scheduled(cron = "${scheduled.buryingPoint}")
    public synchronized void endVip() {
        if (debug) {
            log.warn("本地环境不启动定时");
            return;
        }

        List<BuryingPointDO> list = buryingPointService.drainTo(10000);
        log.debug("存储埋点数据 list = {}", list);
        if(!list.isEmpty()){
            buryingPointService.save(list);
        }
    }

}